<template>
  <el-menu
    :default-active="this.$store.state.menus.editableTabsValue"
    class="el-menu-vertical-demo"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
    style="width:200px"
  >
    <router-link to="/index">
      <el-menu-item
        index="Index"
        @click="selectMenu({ name: '首页', title: '首页' })"
      >
        <template slot="title">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </template>
      </el-menu-item>
    </router-link>
    <el-submenu
      :index="menu.id"
      :key="menu.id"
      v-for="menu in menuList"
      style="width:200px"
    >
      <template slot="title">
        <i :class="menu.icon"></i>
        <span>{{ menu.title }}</span>
      </template>
      <router-link :to="item.path" :key="item.id" v-for="item in menu.children">
        <el-menu-item :index="item.id" @click="selectMenu(item)">
          <template slot="title">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </template>
        </el-menu-item>
      </router-link>
    </el-submenu>
  </el-menu>
</template>
<script>
export default {
  name: "SideMenu",
  data() {
    return {};
  },
  computed: {
    menuList: {
      get() {
        return this.$store.state.menus.menuList;
      },
    },
  },
  methods: {
    selectMenu(item) {
      console.log("selectMenu", item);
      const { title } = item;
      console.log({ name: title, title })
      this.$store.commit("addTab", { name: title, title });
    },
  },
};
</script>
<style scoped>
.el-menu-vertical-demo {
  height: 100%;
}
</style>
